# 判断是否是闰年
def isleap(year):
    return (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0)


# 获取月份天数
def getMaxDays(year, month):
    d = 30
    if month in [1, 3, 5, 7, 8, 10, 12]:
        d = 31
    elif month == 2:
        d = 29 if isleap(year) else 28
    return d

# print(getMaxDays(2021,2))
# import  calendar
# calendar.setfirstweekday(firstweekday=0)
# print(calendar.month(2021,9))
# 获取这一天是当年的第几天
def countDays(y, m, d):
    days = d
    for i in range(1, m):
        days += getMaxDays(y, i)
    return days


def countWeek(y, m):
    w = (y - 1) + (y - 1) // 400 + (y - 1) // 4 - (y - 1) // 100 + countDays(y, m, 1)
    return w % 7


def printMonth(y, m):
    w = countWeek(y, m)
    md = getMaxDays(y, m)
    print("%-6s%-6s%-6s%-6s%-6s%-6s%-6s" % ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
          )
    for i in range(w):
        print("%-6s" % " ", end="")
    for d in range(1, md + 1):
        print(f"{d:<6}", end="")
        w = w + 1
        if w % 7 == 0:
            print()
    print()
